fix memory leaks in coto, geoniche, humminbird, xol.
authortsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 9 Aug 2013 23:47:33 +0000 (23:47 +0000)
committertsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 9 Aug 2013 23:47:33 +0000 (23:47 +0000)
gpsbabel/coto.cc
gpsbabel/geoniche.cc
gpsbabel/humminbird.cc
gpsbabel/xol.cc

index 99956abcb32cfaf2a10c35b73521d48fadf6e1b9..b91be5d837c61d22b87dc311e917289eaa8068c1 100644 (file)
@@ -138,12 +138,17 @@ wr_init(const char* fname)
 static void
 wr_deinit(void)
 {
+  // pdb_close() will only free appinfo in read mode, and pdb_create() sets the mode to write.
+  struct appinfo* ai = (struct appinfo*) file_out->appinfo;
   pdb_close(file_out);
+  if (ai) {
+    free(ai);
+  }
 }
 
 /* helpers */
 
-static char*
+static QString
 coto_get_icon_descr(int category, const appinfo_t* app)
 {
   char buff[CATEGORY_NAME_LENGTH + 1] = "Not Assigned";
@@ -154,10 +159,10 @@ coto_get_icon_descr(int category, const appinfo_t* app)
 
     strncpy(buff, app->categories[category], sizeof(buff) - 1);
     if (buff[0] == '\0') {
-      return NULL;
+      return QString();
     }
   }
-  return xstrdup(buff);
+  return QString(buff);
 }
 
 static void
index 2c9f4610bd12d2cfe3f17049a7937fcda4cc328b..a983ba5bd3bfbd5920281cb8e21060e57656bcd1 100644 (file)
@@ -218,7 +218,7 @@ geoniche_read_asc(void)
     int                id;
     int                route_id;
     char*              title;
-    char*              category;
+    QString            category;
     double             lat, lon, alt;
     char*              datestr, *timestr;
     int                icon;
@@ -277,6 +277,7 @@ geoniche_read_asc(void)
       fatal(MYNAME ": Premature EOD processing field 5 (Category).\n");
     }
     category = p;
+       xfree(p);
 
     /* Field 6: Latitude */
     p = field(&vdata, &vlen);
index d6584357aecf7a5122f4bacfcbf7b00918dca2fc..73b0785730a5700cdf3db8843b30fad4b81a757d 100644 (file)
@@ -309,6 +309,7 @@ humminbird_read_wpt(gbfile* fin)
   // that describes a sub-status
   switch (w.status) {
   case 0: // Waypoint not used.  So why do we have one?
+    waypt_free(wpt);
     break;
   case 1: // Waypoint permanent.
   case 2: // Waypoint temporary.
@@ -319,6 +320,7 @@ humminbird_read_wpt(gbfile* fin)
   case 17: // Waypoint group body.
   case 63: // Waypoint group invalid.
   default:
+    waypt_free(wpt);
     break;
   }
 
index 12eb92d5caaddcd708f62664d01241d2ea199cc7..6f9c41c38abc008e09997e42a896024e65cdcde6 100644 (file)
@@ -100,7 +100,7 @@ xol_shape(const char *args, const QXmlStreamAttributes* attrv)
     }
 
     if (attrv->hasAttribute("icon")) {
-      wpt->icon_descr = xstrdup(attrv->value("icon").toString().toUtf8().constData());
+      wpt->icon_descr = attrv->value("icon").toString();
     }
   }
 }